package com.nus.fellowmark.modules.assignment.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.nus.fellowmark.common.response.ServerResponseEntity;
import com.nus.fellowmark.entity.AssignmentEntity;
import com.nus.fellowmark.modules.assignment.dto.AssignmentDTO;
import com.nus.fellowmark.modules.assignment.dto.DeleteByIdsDTO;
import com.nus.fellowmark.modules.assignment.dto.UpdateAssignmentDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.nus.fellowmark.modules.assignment.service.AssignmentService;
import com.nus.fellowmark.common.utils.PageUtils;



/**
 * 
 *
 * @author Chen Ruoyi
 * @email chenruoyisz@gmail.com
 * @date 2023-02-10  
 */
@RestController
@RequestMapping("assignment")
public class AssignmentController {
    @Autowired
    private AssignmentService assignmentService;

    @SaCheckLogin
    @ApiOperation("List assignments")
    @RequestMapping("/list")
    public ServerResponseEntity list(@RequestParam Map<String, Object> params){
        PageUtils page = assignmentService.queryPage(params);

        return ServerResponseEntity.success("page", page);
    }

    @SaCheckLogin
    @ApiOperation("select assignment by id")
    @RequestMapping("/info/{id}")
    public ServerResponseEntity info(@PathVariable("id") Integer id){
		AssignmentEntity assignment = assignmentService.getById(id);

        return ServerResponseEntity.success("assignment", assignment);
    }

    @ApiOperation("save assignment")
    @RequestMapping("/addAssignment")
    public ServerResponseEntity addAssignment(@RequestBody AssignmentDTO assignmentDTO){
        AssignmentEntity assignmentEntity = assignmentService.addAssignment(assignmentDTO);
        return ServerResponseEntity.success(assignmentEntity);
    }

    @ApiOperation("update assignment")
    @RequestMapping("/updateAssignment")
    public ServerResponseEntity updateAssignment(@RequestBody UpdateAssignmentDTO updateAssignmentDTO){
		assignmentService.updateAssignment(updateAssignmentDTO);

        return ServerResponseEntity.success();
    }

    @ApiOperation("list assignment")
    @RequestMapping("/listAssignment")
    public ServerResponseEntity listAssignment(@RequestParam Integer moduleId) {
        List<AssignmentEntity> assignments = assignmentService.listAssignment(moduleId);
        return ServerResponseEntity.success(assignments);
    }

    @ApiOperation("delete assignment")
    @RequestMapping("/deleteAssignment")
    public ServerResponseEntity deleteAssignment(@RequestBody DeleteByIdsDTO deleteAssignmentDTO){
		assignmentService.removeByIds(Arrays.asList(deleteAssignmentDTO.getIds()));

        return ServerResponseEntity.success();
    }

}
